package com.kingdee.pda.ui.inner_replenish;

import android.content.Context;

import com.example.basecommon.http.MyObserver;
import com.example.basecommon.http.RxHelper;
import com.example.basecommon.http.rxjava.BaseResponse;
import com.example.basecommon.http.rxjava.HttpUtils;
import com.example.basecommon.utils.ConstantUtil;
import com.kingdee.pda.Api;
import com.kingdee.pda.entity.ReplenishCommitBean;
import com.kingdee.pda.entity.ReplenishOrderBean;
import com.kingdee.pda.entity.ReplenishOrderDetailBean;

import java.util.HashMap;
import java.util.List;

/**
 * @author：dlj
 * @data：2021/6/30 17:51
 * @des：库内补货Presenter
 */
public class InnerReplenishPresenter implements InnerReplenishContract.IInnerReplenishPresenter {
    private Context context;
    private InnerReplenishContract.IInnerReplenishView view;

    public InnerReplenishPresenter(Context context, InnerReplenishContract.IInnerReplenishView view) {
        this.context = context;
        this.view = view;
    }

    public void queryReplenishOrderList(String status, String billNo, long warehouseId, int pageSize, int pageIndex) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("warehouseId", warehouseId);
        map.put("pageSize", pageSize);
        map.put("pageIndex", pageIndex);
        map.put("billStatus", status);
        map.put("billNo", billNo);
        MyObserver<List<ReplenishOrderBean.DataBean>> myObserver = new MyObserver<List<ReplenishOrderBean.DataBean>>(context) {
            @Override
            public void onSuccess(BaseResponse<List<ReplenishOrderBean.DataBean>> result) {
                view.onGetOrderSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.onGetOrderFailed(msg);
            }
        };
        HttpUtils.request(Api.class)
                .getRepleOrderList(ConstantUtil.REPLEORDER_GETLIST, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void queryReplenishOrderDetail(long warehouseId, String billNo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("warehouseId", warehouseId);
        map.put("billNo", billNo);
        MyObserver<ReplenishOrderDetailBean.DataBean> myObserver = new MyObserver<ReplenishOrderDetailBean.DataBean>(context) {
            @Override
            public void onSuccess(BaseResponse<ReplenishOrderDetailBean.DataBean> result) {
                view.queryReplenishOderDetailSuccess(result.data);
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.queryReplenishOderDetailFailed(msg);
            }
        };

        HttpUtils.request(Api.class)
                .getRepleOrderDetail(ConstantUtil.REPLENISH_GETORDERDETAIL, map)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }

    @Override
    public void replenishOrderCommit(ReplenishCommitBean commitList) {
        MyObserver myObserver = new MyObserver(context) {
            @Override
            public void onSuccess(BaseResponse result) {
                view.replenishOrderCommitSuccess("补货成功！");
            }

            @Override
            public void onFailure(BaseResponse result, String msg) {
                view.replenishOrderCommitFailed(msg);
            }
        };

        HttpUtils.request(Api.class)
                .repleOrderCommit(ConstantUtil.REPLENISH_COMMIT, commitList)
                .compose(RxHelper.observableIO2Main(context))
                .subscribe(myObserver);
    }
}



